<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/10/19
 * Time: 下午2:12
 */

namespace app\activity\controller;


use think\Request;

class Order extends Auth
{
    /**
     * @purpose 取消出行人（支付之后）
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelTravelByPay (Request $request)
    {
        $attach_id      = $request->post('attach_id', '');
        $reason         = $request->post('reason', '');
        return \app\activity\logic\Order::cancelTravelByPay($attach_id, $reason);
    }
    /**
     * @purpose 未支付时取消订单
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelByNotPay (Request $request)
    {
        $order_no       = $request->post('order_no', '');
        $reason         = $request->post('reason', '');
        return \app\activity\logic\Order::cancelByNotPay($order_no, $reason, self::$uid);
    }

    /**
     * @purpose 申请取消已支付订单
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelByPay (Request $request)
    {
        $order_no       = $request->post('order_no', '');
        $reason         = $request->post('reason', '');
        return \app\activity\logic\Order::cancelByPay($order_no, $reason, self::$uid);
    }

    /**
     * @purpose 订单未支付时取消出行人
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function cancelTravelByNotPay (Request $request)
    {
        $attach_id      = $request->post('attach_id', '');
        $reason         = $request->post('reason', '');
        return \app\activity\logic\Order::cancelTravelByNotPay($attach_id, $reason);
    }
    /**
     * @purpose 取消出行人
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
//    public function cancelTravel (Request $request)
//    {
//        $attach_id      = $request->post('attach_id');
//        return \app\activity\logic\Order::cancelTravel($attach_id, self::$uid);
//    }
    /**
     * @purpose 获取订单详情
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detail (Request $request) {
        $order_no       = $request->get('order_no');
        return \app\activity\logic\Order::detail($order_no, self::$uid);
    }
    /**
     * @purpose 获取列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function items (Request $request)
    {
        $status     = $request->get('status', 1);
        $page       = $request->get('page', 1);
        $size       = $request->get('size', 20);
        return \app\activity\logic\Order::items($status, $page, $size, self::$uid);
    }

    /**
     * @purpose 获取最新出行订单
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function newOrderItems ()
    {
        return \app\activity\logic\Order::newOrderItems(self::$uid);
    }
    /**
     * @purpose 获取不同状态订单数量
     * @return array
     */
    public function total ()
    {
        return \app\activity\logic\Order::total(self::$uid);
    }
    /**
     * @purpose 创建出行订单
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function create (Request $request)
    {
        $data       = $request->post();
        return \app\activity\logic\Order::create($data, self::$uid);
    }
}